From: Claudio Cambra Date: Wed, 4 Dec 2024 08:34:57 +0000 (+0800) Subject: shell_integration/macOS/FileProviderExt: Adapt to API changes in NextcloudFileProvide... X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~2^2~90^2~5 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success/%22http:/www.example.com/cgi/success?a=commitdiff_plain;h=a08a4250834b2d43569ec0100d8a33bc26aedace;p=nextcloud-desktop.git shell_integration/macOS/FileProviderExt: Adapt to API changes in NextcloudFileProviderKit changes in 2.0 Signed-off-by: Claudio Cambra --- diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift index 2a7e5d8e5..68a3981f3 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift @@ -107,14 +107,25 @@ extension FileProviderExtension: NSFileProviderServicing, ChangeNotificationInte @objc func setupDomainAccount( user: String, userId: String, serverUrl: String, password: String ) { + let account = Account(user: user, id: userId, serverUrl: serverUrl, password: password) + guard account != ncAccount else { return } + Task { - let authTestNcKit = NextcloudKit() - authTestNcKit.setup(user: user, userId: userId, password: password, urlBase: serverUrl) + ncKit.appendSession( + account: account.ncKitAccount, + urlBase: serverUrl, + user: user, + userId: userId, + password: password, + userAgent: "Nextcloud-macOS/FileProviderExt", + nextcloudVersion: 25, + groupIdentifier: "" + ) var authAttemptState = AuthenticationAttemptResultState.connectionError // default // Retry a few times if we have a connection issue for authTimeout in AuthenticationTimeouts { - authAttemptState = await authTestNcKit.tryAuthenticationAttempt() + authAttemptState = await ncKit.tryAuthenticationAttempt(account: account) guard authAttemptState == .connectionError else { break } Logger.fileProviderExtension.info( @@ -146,22 +157,12 @@ extension FileProviderExtension: NSFileProviderServicing, ChangeNotificationInte } Task { @MainActor in - let newNcAccount = - Account(user: user, id: userId, serverUrl: serverUrl, password: password) - guard newNcAccount != ncAccount else { return } - ncAccount = newNcAccount - ncKit.setup( - account: newNcAccount.ncKitAccount, - user: newNcAccount.username, - userId: newNcAccount.id, - password: newNcAccount.password, - urlBase: newNcAccount.serverUrl, - userAgent: "Nextcloud-macOS/FileProviderExt", - nextcloudVersion: 25, - delegate: nil) // TODO: add delegate methods for self - + ncAccount = account changeObserver = RemoteChangeObserver( - remoteInterface: ncKit, changeNotificationInterface: self, domain: domain + account: account, + remoteInterface: ncKit, + changeNotificationInterface: self, + domain: domain ) ncKit.setup(delegate: changeObserver) signalEnumeratorAfterAccountSetup() diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+Thumbnailing.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+Thumbnailing.swift index 0c7632556..e1eb24caa 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+Thumbnailing.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+Thumbnailing.swift @@ -29,9 +29,15 @@ extension FileProviderExtension: NSFileProviderThumbnailing { ) -> Void, completionHandler: @escaping (Error?) -> Void ) -> Progress { + guard let ncAccount else { + completionHandler(NSFileProviderError(.notAuthenticated)) + return Progress() + } + return NextcloudFileProviderKit.fetchThumbnails( for: itemIdentifiers, requestedSize: size, + account: ncAccount, usingRemoteInterface: self.ncKit, perThumbnailCompletionHandler: perThumbnailCompletionHandler, completionHandler: completionHandler diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift index db5eda2d5..58b3f1d81 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift @@ -20,7 +20,7 @@ import OSLog @objc class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension { let domain: NSFileProviderDomain - let ncKit = NextcloudKit() + let ncKit = NextcloudKit.shared let appGroupIdentifier = Bundle.main.object(forInfoDictionaryKey: "SocketApiPrefix") as? String var ncAccount: Account? var changeObserver: RemoteChangeObserver? @@ -104,7 +104,7 @@ import OSLog request _: NSFileProviderRequest, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void ) -> Progress { - if ncAccount == nil { + guard let ncAccount else { Logger.fileProviderExtension.error( """ Not fetching item for identifier: \(identifier.rawValue, privacy: .public) @@ -112,7 +112,12 @@ import OSLog """ ) completionHandler(nil, NSFileProviderError(.notAuthenticated)) - } else if let item = Item.storedItem(identifier: identifier, remoteInterface: ncKit) { + return Progress() + } + + if let item = Item.storedItem( + identifier: identifier, account: ncAccount, remoteInterface: ncKit + ) { completionHandler(item, nil) } else { completionHandler(nil, NSFileProviderError(.noSuchItem)) @@ -147,7 +152,7 @@ import OSLog return Progress() } - guard ncAccount != nil else { + guard let ncAccount else { Logger.fileProviderExtension.error( """ Not fetching contents for item: \(itemIdentifier.rawValue, privacy: .public) @@ -159,7 +164,9 @@ import OSLog return Progress() } - guard let item = Item.storedItem(identifier: itemIdentifier, remoteInterface: ncKit) else { + guard let item = Item.storedItem( + identifier: itemIdentifier, account: ncAccount, remoteInterface: ncKit + ) else { Logger.fileProviderExtension.error( """ Not fetching contents for item: \(itemIdentifier.rawValue, privacy: .public) @@ -228,6 +235,7 @@ import OSLog contents: url, request: request, domain: self.domain, + account: ncAccount, remoteInterface: ncKit, progress: progress ) @@ -283,7 +291,9 @@ import OSLog return Progress() } - guard let existingItem = Item.storedItem(identifier: identifier, remoteInterface: ncKit) else { + guard let existingItem = Item.storedItem( + identifier: identifier, account: ncAccount, remoteInterface: ncKit + ) else { Logger.fileProviderExtension.error( "Not modifying item: \(ocId, privacy: .public) as item not found." ) @@ -331,7 +341,7 @@ import OSLog "Received delete request for item: \(identifier.rawValue, privacy: .public)" ) - guard ncAccount != nil else { + guard let ncAccount else { Logger.fileProviderExtension.error( "Not deleting item \(identifier.rawValue, privacy: .public), account not set up yet" ) @@ -340,7 +350,9 @@ import OSLog return Progress() } - guard let item = Item.storedItem(identifier: identifier, remoteInterface: ncKit) else { + guard let item = Item.storedItem( + identifier: identifier, account: ncAccount, remoteInterface: ncKit + ) else { Logger.fileProviderExtension.error( "Not deleting item \(identifier.rawValue, privacy: .public), item not found" ) @@ -376,6 +388,7 @@ import OSLog return Enumerator( enumeratedItemIdentifier: containerItemIdentifier, + account: ncAccount, remoteInterface: ncKit, domain: domain, fastEnumeration: config.fastEnumerationEnabled,